{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3fb2ef35",
   "metadata": {},
   "source": [
    "## 列表的高级方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "281d1d38",
   "metadata": {},
   "source": [
    "### 1. copy( )很重要   “赋值” 不等于 “复制” ！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "79935799",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]\n",
    "stu_id_matedata = stu_id\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2a173bd0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Marry', 'Jan', 'Jack']\n",
      "['Mike', 'Marry', 'Jan', 'Jack']\n",
      "names_1： ['Mike', 'Marry', 'Jan', 'Jack', 'youge']\n",
      "names_1复制： ['Mike', 'Marry', 'Jan', 'Jack', 'youge']\n"
     ]
    }
   ],
   "source": [
    "# 简单的复制\n",
    "\n",
    "names_1 = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "\n",
    "names_1复制 = names_1\n",
    "print(names_1)\n",
    "print(names_1复制)\n",
    "names_1.append(\"youge\")\n",
    "print(\"names_1：\",names_1)\n",
    "print(\"names_1复制：\",names_1复制)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "28cdb3bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Marry', 'Jan', 'Jack']\n",
      "['Mike', 'Marry', 'Jan', 'Jack']\n",
      "names_1： ['Mike', 'Marry', 'Jan', 'Jack', 'youge']\n",
      "names_1复制： ['Mike', 'Marry', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "# 引入 copy()\n",
    "\n",
    "names_1 = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "\n",
    "names_1复制 = names_1.copy()\n",
    "print(names_1)\n",
    "print(names_1复制)\n",
    "names_1.append(\"youge\")\n",
    "print(\"names_1：\",names_1)\n",
    "print(\"names_1复制：\",names_1复制)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7a39bf31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Marry', 'Jan', 'Jack']\n",
      "['Mike', 'Marry', 'Jan', 'Jack']\n",
      "names_1： ['Mike', 'Marry', 'Jan', 'Jack', 'youge']\n",
      "names_1复制： ['Mike', 'Marry', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "# 用切片 [:] 等价于 copy()的方法\n",
    "\n",
    "names_1 = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "\n",
    "names_1复制 = names_1[:]\n",
    "print(names_1)\n",
    "print(names_1复制)\n",
    "names_1.append(\"youge\")\n",
    "print(\"names_1：\",names_1)\n",
    "print(\"names_1复制：\",names_1复制)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5047168e",
   "metadata": {},
   "source": [
    "### 2. len( )查看list长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f6c7dc1d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "names的长度/names的列表元素个数： 4\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "print(\"names的长度/names的列表元素个数：\",len(names))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7db42d8",
   "metadata": {},
   "source": [
    "### 3. in 查看元素是否存在list当中,结果为布尔值，False/True,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d791ff51",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "print(\"zhichao\" in names)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
